package org.example;

import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

public class homework1 {
    public static void main(String[] args) throws InterruptedException {
        int[] arr=new int[10000000];
        Random random=new Random();
        AtomicLong count= new AtomicLong();
        for(int i=0;i<arr.length;i++){
            arr[i]=random.nextInt(100);
        }
        Thread t1 = new Thread(()->{
            for(int i=1;i<arr.length;i+=2){
                count.addAndGet(arr[i]);
            }
        });
        Thread t2 = new Thread(()->{
            for(int i=0;i<arr.length;i+=2){
                count.addAndGet(arr[i]);
            }
        });
        long tt1=System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long tt2=System.currentTimeMillis();
        System.out.println("最终结果="+count);
        System.out.println("运行时间："+(tt2-tt1));
    }
}
